package editor;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;

public class SpriteButton extends JButton {
	private Image immagine;
	private Toolkit tool = Toolkit.getDefaultToolkit();
	private String path;
	
	/**
	 * Crea un nuovo SpriteButton.
	 * @param path percorso dell'icona da assegnare ad un oggetto SpriteButton.
	 */
	public SpriteButton(String path){
		super();
		this.path = path;
		immagine = tool.getImage(this.path);
		this.setIcon(new ImageIcon(immagine));
		this.setPreferredSize(new Dimension(50,50));
	}
	
	public Image getImmagine (){
		return immagine;
	}
	
	public char getSimbolo(){
		String split[] = path.split(File.pathSeparator);
		String temp = split[split.length - 1];
		int indice = temp.indexOf('_');
		return temp.charAt(indice +1);
	}
	public String getFileName(){
		String name[] = this.path.split("/");
		return name[name.length-1];
	}
}